package com.py.pythink.controller;


import com.py.pythink.config.SystemConfig;
import com.py.pythink.third.AliOssUtil;
import com.py.pythink.util.DataUtil;
import com.py.pythink.util.FileUtil;
import com.py.pythink.vo.R;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Date;

/**
 * @program: IdlerApi
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-07-05 17:06
 */

public class VideoControlller {

    @PostMapping("/upload.do")
    public R upload(MultipartFile file) throws IOException {
        if(!file.isEmpty()){
            String objName= FileUtil.rename(file.getOriginalFilename());
            Date date= DataUtil.getDate(SystemConfig.OSS_URL_DAYS);
            String url= AliOssUtil.upload(objName,date,file.getInputStream());
            if(StringUtils.hasLength(url)){
                //上传成功
                return R.ok(url);
            }
        }
        return R.fail();
    }
}
